<!DOCTYPE html>
<html lang="en">
<head>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,Chrome=1"/>
    <meta http-equiv="X-UA-Compatible" content="IE=9"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
	<meta charset="utf-8">
	<title>组合模式</title>
	<script type="text/javascript" src="js/commonUtil.js"></script>
</head>
<body>
<script type="text/javascript">
	
	/*
	 * 场景模拟
	 *
	 *	-> 公司
	 *		-> 开发部
	 *			-> z1
	 *			-> z2
	 *			-> z3
	 *		-> 销售部
	 *			-> z4
	 *			-> z5
	 *			-> z6
	 *
	 *	实际的任务是落实到人上实施的
	 */

	/*
	// 树状结构
	var Org = function (nane) {
		this.name = name;
		this.depts = [];
	}
	Org.prototype = {
		addDept: function (dept) {
			this.depts.push(dept);
			return this;
		},
		getDept: function () {
			return this.depts;
		}
	}

	var Dept = function (name) {
		this.name = name;
		this.persons = [];
	}
	Dept.prototype = {
		addPerson: function (person) {
			this.persons.push(person);
			return this;
		},
		getPersons: function () {
			return this.persons;
		}
	}
	Object.defineProperty(Dept.prototype, 'constructor', {
		enumerable: false, //设置能否被枚举
		value: Dept
	})

	var Person = function (name) {
		this.name = name
	}
	Person.prototype = {
		hardworking: function () {
			document.write(this.name + '...努力工作');
		},
		sleeping: function () {
			document.write(this.name + '...努力睡觉');
		}
	}
	Object.defineProperty(Person.prototype, 'constructor', {
		enumerable: false, //设置能否被枚举
		value: Person
	})

	var p1 = new Person('z1');
	var p2 = new Person('z2');
	var p3 = new Person('z3');
	var p4 = new Person('z4');
	var p5 = new Person('z5');
	var p6 = new Person('z6');

	var dept1 = new Dept('开发部');
	dept1.addPerson(p1).addPerson(p2).addPerson(p3);

	var dept2 = new Dept('销售部');
	dept2.addPerson(p4).addPerson(p5).addPerson(p6);

	var org = new Org('myjerry');
	org.addDept(dept1).addDept(dept2);

	console.log(org.getDept()[0].getPersons()[0].hardworking());
	*/
</script>
</body>
</html>